<template>
	<view class="">
		<view class="pagesBg"></view>
		<view class="pagesBox">
			<block v-for="(item,index) in bankList" :key="index">
				<view class="bankItem" @click="choose(item)">
					<view class="userInfoBox">
						<view class="userInfoMain2">
							<!-- <view class="imageBox"><image src="/static/logo.png" style="width: 80rpx;height: 80rpx;"></image></view> -->
							<view class="infoMain">
								<view class="infoName">{{item.bank_name}}</view>
								<view class="infoTime">{{item.true_name}}</view>
							</view>
						</view>
						<view class="infoBtn" @click.stop="delBank(item)">
							<text style="margin-left: 8rpx;">解绑</text>
						</view>
					</view>
					<view class="bankNo">
						<view class="mr30">****</view>
						<view class="mr30">****</view>
						<view class="mr30">****</view>
						<view>{{item.account.substr(-4)}}</view>
					</view>
				</view>
			</block>
			<view class="addCarBox" @click="toAddBank">
				<uni-icons type="plus" size="26" color="#444C55"></uni-icons>
				<view>添加银行卡</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl:this.$baseUrl,
				params:{
					page:1,
					listRows:15,
				},
				bankList:[],
				comePage:''
			};
		},
		onLoad(options) {
			this.comePage = options.comePage;
		},
		onShow() {
			this.getBankList()
		},
		methods:{
			async getBankList(){
				let res = await uni.$http('POST','Bank/all',this.params);
				console.log('银行卡列表',res);
				if(res.code == 1){
					this.bankList = res.data;
					// this.params.page = res.data.current_page;
					// this.total = res.data.total;
					// if(this.params.page == 1){
					// 	this.bankList = res.data.data;
					// }else{
					// 	this.bankList = this.bankList.concat(res.data.data);
					// }
					// if(this.bankList.length < this.total){
					// 	this.statusType = 'more'
					// }else{
					// 	this.statusType = 'noMore'
					// }
				}else if(res.msg.includes('登录')){
					this.total = 0;
					uni.removeStorageSync('token')
				}else{
					this.total = 0;
				}
			},
			async delBank(item){
				let num = item.account.substr(-4);
				uni.showModal({
					title: '提示',
					content: `确定解绑尾号为${num}的银行卡吗？`,
					success: async (res)=> {
						if (res.confirm) {
							let res = await uni.$http('POST','Bank/delete',{id:item.id});
							console.log('解绑银行卡',res);
							uni.$u.toast(res.msg)
							if(res.code == 1){
								this.getBankList()
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			choose(item){
				console.log(item);
				if(this.comePage == 'payouts'){
					let pages = getCurrentPages()
					let prePage = pages[pages.length - 2];
					prePage.$vm.bankName = item.bank_name;
					prePage.$vm.params.brank_id = item.id;
					prePage.$vm.isRefresh = false;
					uni.navigateBack()
				}
			},
			toAddBank(){
				uni.navigateTo({
					url:"/pagesMy/storeManage/addBank"
				})
			}
		},
		onReachBottom() {
			if(this.bankList.length < this.total){
				this.statusType = 'loading';
				this.params.page++;
				// this.getBankList()
			}else{
				this.statusType = 'noMore'
			}
		}
	}
</script>

<style scoped lang="scss">
	.pagesBg {
		height: 300rpx;
		background: linear-gradient(#04449e 0% , #F7F8FA 100%);
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
	}
.pagesBox{
	padding: 12rpx 24rpx;
	position: relative;
	.bankItem{
		background-color: #33629D;
		border-radius: 12rpx;
		padding: 12rpx 24rpx;
		margin-bottom: 16rpx;
		.userInfoBox{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.userInfoMain2{
				color: #fff;
				display: flex;
				align-items: center;
				.imageBox{
					width: 80rpx;
					height: 80rpx;
					font-size: 0%;
					border-radius: 50%;
					margin-right: 16rpx;
					overflow: hidden;
				}
				.infoMain{
					.identityBox{
						display: flex;
						align-items: center;
						.btn{
							font-weight: 400;
							font-size: 20rpx;
							color: #fff;
							padding: 2rpx 8rpx;
							background: #04449E;
							border-radius: 8rpx;
						}
					}
					.infoName{
						font-weight: 600;
						font-size: 30rpx;
						color: #fff;
						display: flex;
						align-items: center;
					}
					.infoTime{
						font-weight: 400;
						font-size: 24rpx;
						color: #f8f8f8;
						margin-top: 6rpx;
					}
				}
			}
			.infoBtn{
				width: 128rpx;
				height: 48rpx;
				font-weight: 600;
				font-size: 26rpx;
				color: #04449E;
				background: #EBF3FF;
				border-radius: 36rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
		.bankNo{
			font-weight: 600;
			font-size: 46rpx;
			color: #FFFFFF;
			margin-top: 48rpx;
			letter-spacing: 2rpx;
			display: flex;
			align-items: center;
			.mr30{
				margin-right: 30rpx;
			}
		}
	}
	.addCarBox{
		height: 160rpx;
		font-weight: 400;
		font-size: 32rpx;
		color: #444C55;
		background-color: #fff;
		border-radius: 16rpx;
		padding: 24rpx;
		display: flex;
		align-items: center;
	}
}
</style>
<style>
	page{
		background-color: #F7F8FA;
	}
</style>